package com.fjrcloud.controller;

import com.fjrcloud.entity.*;
import com.fjrcloud.exception.BusinessException;
import com.fjrcloud.service.HouseholdService;
import com.fjrcloud.service.RelocationTransitionService;
import com.fjrcloud.utils.StatusUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by shengjian.lin on 17-2-15.
 */
@Controller
@RequestMapping("api/relocationTransition")
public class RelocationTransitionController {

    @Autowired
    private RelocationTransitionService service;
    @Autowired
    private HouseholdService householdService;

    @RequestMapping("save")
    @ResponseBody
    public ResponseBean save(RelocationTransition entity,Integer masterId) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.save(entity,masterId));
    }
    @RequestMapping("get")
    @ResponseBody
    public ResponseBean get(Integer masterId) throws BusinessException {

        if (masterId == null)
            throw new BusinessException("主体错误");
        HouseholdMaster master = householdService.getMaster(masterId);
        if (master == null)
            throw new BusinessException("主体错误");

        return ResponseFactory.getResponseBean(StatusUtils.Success,service.get(master));
    }
}
